from base import By, webdriver, sleep

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')


# 打开新闻标签页
sleep(2)
driver.find_element(By.LINK_TEXT, '新闻').click()
print(driver.title)

# 切换标签页到新闻页
sleep(2)
news_handle = driver.window_handles[1]
driver.switch_to.window(news_handle)
print(driver.title)

# 切换标签页到首页
sleep(2)
home_handle = driver.window_handles[0]
driver.switch_to.window(home_handle)
print(driver.title)

# 退出浏览器
driver.quit()
